"""Card 类代表 张牌，其中 FaceNum 宇段指的是牌面数字 13, Suit 字段指的是花色，
值“梅”为梅花、“方”为方钻 “红”为红心、“黑”为黑桃。"""


class Card():
    RANKS = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
    SUITS = ['梅', '方', '红', '黑']

    def __init__(self, rank, suit, face_up=True):
        self.rank = rank  # 牌面数字
        self.suit = suit  # 花色
        self.face_up = face_up  # 是否朝上显示

    def __str__(self):  # 重写print()方法，打印一张牌的信息
        if self.face_up:
            rep = self.rank + self.suit
        else:
            rep = 'XX'
        return rep

    def pic_order(self):  # 牌的顺序号
        if self.rank == 'A':
            FaceNum = 14
        elif self.rank == 'J':
            FaceNum = 11
        elif self.rank == 'Q':
            FaceNum = 12
        elif self.rank == 'K':
            FaceNum = 13
        else:
            FaceNum = int(self.rank)

        if self.suit == '梅':
            SuitNum = 1
        elif self.suit == '方':
            SuitNum = 2
        elif self.suit == '红':
            SuitNum = 3
        elif self.suit == '黑':
            SuitNum = 4
        return (SuitNum - 1) * 13 + FaceNum

    def flip(self):  # 翻牌
        self.face_up = not self.face_up
